home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / share / initramfs-tools / init < prev    next >
Text File  |  2008-08-13  |  4KB  |  233 lines

  1. #!/bin/sh
  2.  
  3. echo "Loading, please wait..."
  4.  
  5. [ -d /dev ] || mkdir -m 0755 /dev
  6. [ -d /root ] || mkdir -m 0700 /root
  7. [ -d /sys ] || mkdir /sys
  8. [ -d /proc ] || mkdir /proc
  9. [ -d /tmp ] || mkdir /tmp
  10. mkdir -p /var/lock
  11. mount -t sysfs -o nodev,noexec,nosuid none /sys 
  12. mount -t proc -o nodev,noexec,nosuid none /proc 
  13.  
  14. # Note that this only becomes /dev on the real filesystem if udev's scripts
  15. # are used; which they will be, but it's worth pointing out
  16. mount -t tmpfs -o mode=0755 udev /dev
  17. [ -e /dev/console ] || mknod -m 0600 /dev/console c 5 1
  18. [ -e /dev/null ] || mknod /dev/null c 1 3
  19. > /dev/.initramfs-tools
  20. mkdir /dev/.initramfs
  21.  
  22. # Export the dpkg architecture
  23. export DPKG_ARCH=
  24. . /conf/arch.conf
  25.  
  26. # Set modprobe env
  27. export MODPROBE_OPTIONS="-Qb"
  28.  
  29. # Export relevant variables
  30. export ROOT=
  31. export ROOTDELAY=
  32. export ROOTFLAGS=
  33. export ROOTFSTYPE=
  34. export break=
  35. export init=/sbin/init
  36. export quiet=n
  37. export readonly=y
  38. export rootmnt=/root
  39. export debug=
  40. export panic=
  41. export blacklist=
  42. export resume_offset=
  43.  
  44. # Bring in the main config
  45. . /conf/initramfs.conf
  46. for conf in conf/conf.d/*; do
  47.     [ -f ${conf} ] && . ${conf}
  48. done
  49. . /scripts/functions
  50.  
  51. # Parse command line options
  52. for x in $(cat /proc/cmdline); do
  53.     case $x in
  54.     init=*)
  55.         init=${x#init=}
  56.         ;;
  57.     root=*)
  58.         ROOT=${x#root=}
  59.         case $ROOT in
  60.         LABEL=*)
  61.             ROOT="/dev/disk/by-label/${ROOT#LABEL=}"
  62.             ;;
  63.         UUID=*)
  64.             ROOT="/dev/disk/by-uuid/${ROOT#UUID=}"
  65.             ;;
  66.         /dev/nfs)
  67.             [ -z "${BOOT}" ] && BOOT=nfs
  68.             ;;
  69.         esac
  70.         ;;
  71.     rootflags=*)
  72.         ROOTFLAGS="-o ${x#rootflags=}"
  73.         ;;
  74.     rootfstype=*)
  75.         ROOTFSTYPE="${x#rootfstype=}"
  76.         ;;
  77.     rootdelay=*)
  78.         ROOTDELAY="${x#rootdelay=}"
  79.         case ${ROOTDELAY} in
  80.         *[![:digit:].]*)
  81.             ROOTDELAY=
  82.             ;;
  83.         esac
  84.         ;;
  85.     resumedelay=*)
  86.         RESUMEDELAY="${x#resumedelay=}"
  87.         ;;
  88.     loop=*)
  89.         LOOP="${x#loop=}"
  90.         ;;
  91.     loopflags=*)
  92.         LOOPFLAGS="-o ${x#loopflags=}"
  93.         ;;
  94.     loopfstype=*)
  95.         LOOPFSTYPE="${x#loopfstype=}"
  96.         ;;
  97.     cryptopts=*)
  98.         cryptopts="${x#cryptopts=}"
  99.         ;;
  100.     nfsroot=*)
  101.         NFSROOT="${x#nfsroot=}"
  102.         ;;
  103.     netboot=*)
  104.         NETBOOT="${x#netboot=}"
  105.         ;;
  106.     ip=*)
  107.         IPOPTS="${x#ip=}"
  108.         ;;
  109.     boot=*)
  110.         BOOT=${x#boot=}
  111.         ;;
  112.     resume=*)
  113.         RESUME="${x#resume=}"
  114.         ;;
  115.     resume_offset=*)
  116.         resume_offset="${x#resume_offset=}"
  117.         ;;
  118.     noresume)
  119.         noresume=y
  120.         ;;
  121.     panic=*)
  122.         panic="${x#panic=}"
  123.         case ${panic} in
  124.         *[![:digit:].]*)
  125.             panic=
  126.             ;;
  127.         esac
  128.         ;;
  129.     quiet)
  130.         quiet=y
  131.         ;;
  132.     ro)
  133.         readonly=y
  134.         ;;
  135.     rw)
  136.         readonly=n
  137.         ;;
  138.     debug)
  139.         debug=y
  140.         quiet=n
  141.         exec >/tmp/initramfs.debug 2>&1
  142.         set -x
  143.         ;;
  144.     debug=*)
  145.         debug=y
  146.         quiet=n
  147.         set -x
  148.         ;;
  149.     break=*)
  150.         break=${x#break=}
  151.         ;;
  152.     break)
  153.         break=premount
  154.         ;;
  155.     blacklist=*)
  156.         blacklist=${x#blacklist=}
  157.         ;;
  158.     esac
  159. done
  160.  
  161. if [ -z "${noresume}" ]; then
  162.     export resume=${RESUME}
  163. else
  164.     export noresume
  165. fi
  166.  
  167. depmod -a
  168. maybe_break top
  169.  
  170. # export BOOT variable value for compcache,
  171. # so we know if we run from casper
  172. export BOOT
  173.  
  174. # Don't do log messages here to avoid confusing usplash
  175. run_scripts /scripts/init-top
  176.  
  177. maybe_break modules
  178. log_begin_msg "Loading essential drivers..."
  179. load_modules
  180. log_end_msg
  181.  
  182. maybe_break premount
  183. [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-premount"
  184. run_scripts /scripts/init-premount
  185. [ "$quiet" != "y" ] && log_end_msg
  186.  
  187. maybe_break mount
  188. log_begin_msg "Mounting root file system..."
  189. . /scripts/${BOOT}
  190. parse_numeric ${ROOT}
  191. mountroot
  192. log_end_msg
  193.  
  194. maybe_break bottom
  195. [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-bottom"
  196. run_scripts /scripts/init-bottom
  197. [ "$quiet" != "y" ] && log_end_msg
  198.  
  199. # Move virtual filesystems over to the real filesystem
  200. mount -n -o move /sys ${rootmnt}/sys
  201. mount -n -o move /proc ${rootmnt}/proc
  202.  
  203. # Check init bootarg
  204. if [ -n "${init}" ] && [ ! -x "${rootmnt}${init}" ]; then
  205.     echo "Target filesystem doesn't have ${init}."
  206.     init=
  207. fi
  208.  
  209. # Search for valid init
  210. if [ -z "${init}" ] ; then
  211.     for init in /sbin/init /etc/init /bin/init /bin/sh; do
  212.         if [ ! -x "${rootmnt}${init}" ]; then
  213.             continue
  214.         fi
  215.         break
  216.     done
  217. fi
  218.  
  219. # No init on rootmount
  220. if [ ! -x "${rootmnt}${init}" ]; then
  221.     panic "No init found. Try passing init= bootarg."
  222. fi
  223.  
  224. # Confuses /etc/init.d/rc
  225. if [ -n ${debug} ]; then
  226.     unset debug
  227. fi
  228.  
  229. # Chain to real filesystem
  230. maybe_break init
  231. exec run-init ${rootmnt} ${init} "$@" <${rootmnt}/dev/console >${rootmnt}/dev/console 2>&1
  232. panic "Could not execute run-init."
  233.